package com.example.im.bean

import android.os.Parcel
import android.os.Parcelable
import android.text.TextUtils
import cc.vv.lkbasecomponent.util.LKStringUtil
import com.example.baselibrary.bean.pinyin.BaseIndexPinyinBean

/**
 * 群成员实体
 * @author  chaohaipeng  on 2018/7/25.
 */
class GroupMemberObj() : BaseIndexPinyinBean(), Parcelable, Comparable<GroupMemberObj> {


    /*成员ID*/
    var id: String=""
    /* 成员昵称*/
    var nick: String=""
    /*成员头像Url*/
    var faceUrl: String=""
    /*创建时间*/
    var createTime: Long = 0
    /* 本地交互使用,是否被选中*/
    var isSelected = false

    var groupId: String=""
    /**
     * 群主：1，非群主：0
     */
    var isOwner: Int = 0
    /**
     * 拼音昵称
     */
    var pinyinNick: String=""
    /**
     * 拼音昵称首字母
     */
    var firstAlpha: String=""

    private var isTop: Boolean = false//是否是最上面的 不需要被转化成拼音的




    constructor(`in`: Parcel) : this() {
        id = `in`.readString()
        nick = `in`.readString()
        faceUrl = `in`.readString()
        createTime = `in`.readLong()
        isSelected = `in`.readByte().toInt() != 0
        groupId = `in`.readString()
        isOwner = `in`.readInt()
        pinyinNick = `in`.readString()
        firstAlpha = `in`.readString()
    }

    override fun writeToParcel(dest: Parcel, flags: Int) {
        dest.writeString(id)
        dest.writeString(nick)
        dest.writeString(faceUrl)
        dest.writeLong(createTime)
        dest.writeByte((if (isSelected) 1 else 0).toByte())
        dest.writeString(groupId)
        dest.writeInt(isOwner)
        dest.writeString(pinyinNick)
        dest.writeString(firstAlpha)
    }

    override fun describeContents(): Int {
        return 0
    }

    override fun compareTo(another: GroupMemberObj): Int {
        var isSawp = 0
        if (!TextUtils.isEmpty(another.pinyinNick) && !TextUtils.isEmpty(this.pinyinNick)) {
            isSawp = this.pinyinNick.toUpperCase().compareTo(another.pinyinNick.toUpperCase())
        }
        return isSawp
    }
    override fun equals(obj: Any?): Boolean {
        if (obj is GroupMemberObj) {

            val groupMemberObj = obj as GroupMemberObj?
            val groupId = groupMemberObj!!.id
            return if (LKStringUtil.equals(groupId, id)) {
                true
            } else {
                false
            }
        }
        return false
    }
    companion object CREATOR : Parcelable.Creator<GroupMemberObj> {
        override fun createFromParcel(parcel: Parcel): GroupMemberObj {
            return GroupMemberObj(parcel)
        }

        override fun newArray(size: Int): Array<GroupMemberObj?> {
            return arrayOfNulls(size)
        }
    }

    override fun hashCode(): Int {
        return super.hashCode()
    }
    override fun getTarget(): String {
        return nick
    }

    fun isTop(): Boolean {
        return isTop
    }

    fun setTop(top: Boolean): GroupMemberObj {
        isTop = top
        return this
    }
}